//
//  AFMenuItem.m
//  AFChat
//
//  Created by Void on 2018/6/25.
//  Copyright © 2018年 afei. All rights reserved.
//

#import "AFMenuItem.h"
#import <TLTabBarController/TLBadge.h>

AFMenuItem *createMenuItem(NSString *icon, NSString *title) {
    AFMenuItem *item = [[AFMenuItem alloc] init];
    [item setIconName:icon];
    [item setTitle:title];
    return item;
}
@implementation AFMenuItem

- (void)setBadge:(NSString *)badge {
    _badge = badge;
    _badgeSize = [TLBadge badgeSizeWithValue:badge];
}

- (void)setRightIconURL:(NSString *)rightIconURL withRightIconBadge:(BOOL)rightIconBadge {
    [self setRightIconURL:rightIconURL];
    [self setShowRightIconBadge:rightIconBadge];
}

- (BOOL)showRightIconBadge {
    if (!self.rightIconURL) {
        return NO;
    }
    return _showRightIconBadge;
}
@end

@implementation AFMenuItemGrounp

- (instancetype)initWithHeaderTitle:(NSString *)headerTitle footerTitle:(NSString *)footerTitle cellItems:(AFMenuItem *)firstObject, ...
{
    if (self = [super init]) {
        _headerTitle = headerTitle;
        _footerTitle = footerTitle;
        _items = [[NSMutableArray alloc] init];
        va_list argList;
        if (firstObject) {
            [_items addObject:firstObject];
            va_start(argList, firstObject);
            id arg;
            while ((arg = va_arg(argList, id))) {
                [_items addObject:arg];
            }
            va_end(argList);
        }
    }
    return self;
}

- (AFMenuItem *)itemAtIndex:(NSUInteger)index {
    return [_items objectAtIndex:index];
}

- (NSUInteger)indexOfItem:(AFMenuItem *)item {
    return [_items indexOfObject:item];
}

- (NSUInteger)itemsCount {
    return self.items.count;
}

@end
